﻿using APIShoppingSystem.Model;
using IShoppingBll;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using ShoppingEntity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace APIShoppingSystem.Controllers
{
	[Route("api/[controller]/[action]")]
	[ApiController]
	public class ReturnExchangeController : ControllerBase
	{
		private IReturnExchangeBll _returnExchangeBll;

		public ReturnExchangeController(IReturnExchangeBll returnExchangeBll)
		{
			_returnExchangeBll = returnExchangeBll;
		}

        /// <summary>
        /// 退货记录视图展示
        /// </summary>
        /// <param name="page"></param>
        /// <param name="limit"></param>
        /// <param name="state"></param>
        /// <param name="goodsId"></param>
        /// <returns></returns>
       [HttpGet]
        public IActionResult GetReturnExchangeList(int page, int limit, ReturnExchangeStatusEnum state, string CommodityName)
        {
            int count;

            object returnExchange = _returnExchangeBll.GetReturnExchangeListByPage(page, limit, out count, state, CommodityName);

            return new JsonResult(new
            {
                code = 0,
                msg = "成功",
                count = count,
                data = returnExchange
            });
        }


        /// <summary>
        /// 获取流程步骤状态下拉选数据
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult GetStatusSelectOption()
        {
            CustomActionResult res = new CustomActionResult();
            var options = _returnExchangeBll.GetStatusSelectOption();
            res.Datas = options;
            res.IsSuccess = true;
            res.Status = 1;
            return new JsonResult(res);
        }


        /// <summary>
        /// 同意退货物退款
        /// </summary>
        /// <param name="returnExchangeId"></param>
        /// <returns></returns>
        [HttpPost]
        public IActionResult ConsentApply([FromForm]string returnExchangeId)
        {
            CustomActionResult res = new CustomActionResult();
            bool isSuccess = _returnExchangeBll.ConsentApply(returnExchangeId);
            if (isSuccess)
            {
                res.Status = 1;
                res.IsSuccess = true;
                res.Msg = "成功";
            }

            return new JsonResult(res);
        }
    }
    
}
